package model

import (
	"database/sql/driver"
	"encoding/json"
	"fmt"
	"time"
)

type Response struct {
	StatusCode int32  `json:"status_code"`
	StatusMsg  string `json:"status_msg,omitempty"`
}

// User 用户模型
type User struct {
	Id            int64  `gorm:"primary_key;auto_increment" json:"id,omitempty"`
	Name          string `gorm:"unique" json:"name,omitempty"`
	Password      string `json:"password"`
	FollowCount   int64  `json:"follow_count,omitempty"`
	FollowerCount int64  `json:"follower_count,omitempty"`
	IsFollow      bool   `json:"is_follow,omitempty"`
}

// 实现 Valuer 接口
func (u User) Value() (driver.Value, error) {
	return json.Marshal(u)
}

// 实现 Scanner 接口
func (u *User) Scan(value interface{}) error {
	bytes, ok := value.([]byte)
	if !ok {
		return fmt.Errorf("could not scan type %T into User", value)
	}
	return json.Unmarshal(bytes, u)
}

// Video 视频模型
type Video struct {
	Id            int64     `gorm:"primary_key;auto_increment" json:"id,omitempty"`
	Title         string    `json:"title,omitempty"`
	Author        User      `json:"author,omitempty"`
	PlayUrl       string    `json:"play_url,omitempty"`
	CoverUrl      string    `json:"cover_url,omitempty"`
	FavoriteCount int64     `json:"favorite_count,omitempty"`
	CommentCount  int64     `json:"comment_count,omitempty"`
	IsFavorite    bool      `json:"is_favorite,omitempty"`
	CreateAt      time.Time `json:"create_at,omitempty"`
}

type Comment struct {
	Id         int64  `json:"id,omitempty"`
	User       User   `json:"user"`
	Content    string `json:"content,omitempty"`
	CreateDate string `json:"create_date,omitempty"`
}

type Message struct {
	Id         int64  `json:"id,omitempty"`
	Content    string `json:"content,omitempty"`
	CreateTime string `json:"create_time,omitempty"`
}

type MessageSendEvent struct {
	UserId     int64  `json:"user_id,omitempty"`
	ToUserId   int64  `json:"to_user_id,omitempty"`
	MsgContent string `json:"msg_content,omitempty"`
}

type MessagePushEvent struct {
	FromUserId int64  `json:"user_id,omitempty"`
	MsgContent string `json:"msg_content,omitempty"`
}
